package com.erp.base.common.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.springframework.stereotype.Service;

import com.erp.base.base.CrudService;
import com.erp.base.common.dao.DictDao;
import com.erp.base.common.entity.Dict;
import com.erp.base.common.utils.StringUtils;
import com.erp.base.system.entity.User;


@Service("dictService")
public class DictService extends CrudService<DictDao, Dict, Long> {
   
    public String getName(String type, String value) {
        Dict dict=new Dict();
        dict.setType(type);
        dict.setValue(value);
        List<Dict> dictList = this.dao.findList(dict);
        if(dictList==null||dictList.isEmpty()){
        	return "";
        }
        return dictList.get(0).getName();
    }

    public List<Dict> getHobbyList(User userDO) {
    	Dict dict=new Dict();
        dict.setType("hobby");
        List<Dict> hobbyList = this.dao.findList(dict);
        if (StringUtils.isNotEmpty(userDO.getHobby())) {
            String userHobbys[] = userDO.getHobby().split(";");
            for (String userHobby : userHobbys) {
                for (Dict hobby : hobbyList) {
                    if (!Objects.equals(userHobby, hobby.getId().toString())) {
                        continue;
                    }
                    hobby.setRemarks("true");
                    break;
                }
            }
        }
        return hobbyList;
    }

    public List<Dict> getSexList() {
        Dict dict=new Dict();
        dict.setType("sex");
        return this.dao.findList(dict);
    }

    public List<Dict> listByType(String type) {
    	 Dict dict=new Dict();
         dict.setType(type);
         return this.dao.findList(dict);
    }

	public Map<String, List<Dict>> listByTypes(String ...types) {
		Map<String, List<Dict>>data=new HashMap<String, List<Dict>>();
		if(types.length>0){
			for (String type : types) {
				data.put(type, listByType(type));
			}
		}
		return data;
	}
	
	public List<Dict> listType(){
		return dao.listType();
	}
 
}
